package com.inspur.edp.ai.flow.core.engine;

import java.util.concurrent.*;

/**
 * @author lizhaorui
 * @date 2025/11/10
 * @description
 */

public class ThreadPoolService {

    private static ExecutorService executor;

    public static ExecutorService getExecutor() {
        if (executor == null) {
            synchronized (ThreadPoolService.class) {
                if (executor == null) {
                    executor = new ThreadPoolExecutor(
                            2,                              // 核心线程数
                            100,                             // 最大线程数
                            60,                             // 空闲超时时间
                            TimeUnit.SECONDS,               // 时间单位
                            new ArrayBlockingQueue<>(1000),  // 有界队列，容量1000
                            Executors.defaultThreadFactory(), // 默认线程工厂
                            new ThreadPoolExecutor.AbortPolicy() // 拒绝策略：抛出异常
                    );
                }
            }
        }
        return executor;
    }
}